﻿using Xejen.Communication.Configuration;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Text;

namespace Xejen.Communication
{
    /// <summary>
    /// 表示通讯器的心跳
    /// </summary>
    /// <typeparam name="THeartbeatConfig"><inheritdoc cref="Xejen.Communication.Configuration.HeartbeatConfig" path="/summary"/></typeparam>
    /// <creator>marc</creator>
    public interface IHeartbeat<THeartbeatConfig> : IHostedService
        where THeartbeatConfig : HeartbeatConfig, new()
    {
        /// <summary>
        /// 本地在线状态变更时发生
        /// </summary>
        event EventHandler<AliveStatusEventArgs> LocalAliveChanged;
        /// <summary>
        /// 远端在线状态变更时发生
        /// </summary>
        event EventHandler<AliveStatusEventArgs> RemoteAliveChanged;

        /// <inheritdoc cref="Xejen.Communication.Configuration.HeartbeatConfig"/>
        THeartbeatConfig HeartbeatConfig { get; }

        /// <summary>
        /// 本地是否在线
        /// </summary>
        bool IsLocalAlive { get; }
        /// <summary>
        /// 远端是否在线
        /// </summary>
        bool IsRemoteAlive { get; }

        /// <summary>
        /// 远端心跳判断
        /// </summary>
        Func<bool> RemoteHeartbeatCheck { get; set; }
        /// <summary>
        /// 本地心跳判断
        /// </summary>
        Func<bool> LocalHeartbeatCheck { get; set; }
    }
}
